<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>11_代码执行顺序-await的代码</title>
</head>

<body>

  <script>

    console.log("script start")

    function requestData(url) {
      console.log("requestData")
      return new Promise((resolve) => {
        setTimeout(() => {
          console.log("setTimeout")
          resolve(url)
        }, 2000);
      })
    }

    // 2.await/async
    async function getData() {
      console.log("getData start")
      const res = await requestData("await-name")

      console.log("then1-res:", res)
      console.log("getData end")
    }

    getData()

    new Promise((resolve) => {
      console.log("promise")
      resolve()
    }).then(() => {
      console.log("then1")
    })

    console.log("script end")

  </script>

</body>

</html>